﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SqlCon;

namespace yfxt
{
    public partial class gl_ypckd_you : Form
    {
        public gl_ypckd_you()
        {
            InitializeComponent();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void gl_ypckd_you_Load(object sender, EventArgs e)
        {
            dataGridView1.AllowUserToResizeRows = false;                     //禁止用鼠标调整datagridView单元格的大小。
            dataGridView1.AllowUserToResizeColumns = false;
            foreach (DataGridViewColumn c in dataGridView1.Columns)        //禁止对datagridView列进行排序
            {
                c.SortMode = DataGridViewColumnSortMode.NotSortable;
            }

            string chukudanhao = ((gl_ypck)this.Owner).chukudanhao;
            DataTable dt = new DataTable();
            DataTable dt2 = new DataTable();

            //显示No.100001
            label6.Text = chukudanhao;

            //显示入库日期、备注、出库员、复核员
            string comStr = "select t.ckrq,t.ckbz,t1.ygxm,t2.ygxm from YF_cK01 t,GY_YGDM t1,GY_YGDM t2 "+
                "where t.ckdh='" + chukudanhao + "' and t.czgh=t1.ygbh and t.fhy=t2.ygbh";
            dt2.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));
            textBox2.Text = Convert.ToDateTime(dt2.Rows[0][0]).ToString("yyyy-MM-dd").Replace('-', '.');
            textBox3.Text = dt2.Rows[0][1].ToString();
            textBox4.Text = dt2.Rows[0][2].ToString();
            textBox5.Text = dt2.Rows[0][3].ToString();

            //显示合计
            comStr = "select sum(lsje) from yf_ck02 where ckdh='" + chukudanhao + "'";
            string total_lsje = (SqlHelper.ExecuteScalar(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null)).ToString();
            textBox6.Text = total_lsje;

            //显示datagridView1的
            comStr = "select t1.ypmc,t.ypgg,t.yfdw,t2.cdqc,t.lsjg,t.cksl,t.lsje,t.ypph,t.ypxq,t3.fsmc from YF_cK02 t,yk_typk t1,YK_CDDZ t2,YF_cKFS t3 " +
                "where t.ckdh='" + chukudanhao + "' and t.ypxh=t1.ypxh and t2.ypcd=t.ypcd and t3.yfsb=t.yfsb and t3.ckfs=t.ckfs";
            dt.Load(SqlHelper.ExecuteReader(SqlHelper.ConnectionStringLocalTransaction, CommandType.Text, comStr, null));

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                dataGridView1.Rows.Add(1);

                for (int j = 0; j < 9; j++)
                {
                    if (dt.Rows[i][j].ToString() != "")
                    {
                        if (j == 8)
                        {
                            dataGridView1.Rows[i].Cells[j].Value = Convert.ToDateTime(dt.Rows[i][j]).ToString("yyyy-MM-dd").Replace('-', '.');
                        }
                        else
                        {
                            dataGridView1.Rows[i].Cells[j].Value = dt.Rows[i][j].ToString();
                        }
                    }
                }
            }

            //显示出库方式
            textBox1.Text = dt.Rows[0][9].ToString();
        }

    }
}
